package top.korori.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.korori.common.model.PageData;
import top.korori.common.model.Result;
import top.korori.oss.entity.res.CosTmpKeyVo;
import top.korori.sv.entity.bo.*;
import top.korori.sv.entity.vo.SvUserWorkVo;
import top.korori.sv.entity.vo.SvWorkVo;
import top.korori.sv.service.SvWorkService;
import top.korori.sv.uitls.SvSecurityUtil;

/**
 * 作品 前端控制器
 *
 * @author korori
 */

@Api(tags = "作品管理")
@RestController
@RequestMapping("/sv/work")
public class SvWorkController {

    @Autowired
    private SvWorkService svWorkService;

    @ApiOperation("获取首页作品")
    @GetMapping("/getHoneWorks")
    public Result<PageData<SvUserWorkVo>> getHoneWorks(SvHomeWorkGetBo svHomeWorkGetBo) {
        PageData<SvUserWorkVo> pageData = svWorkService.getHoneWorks(svHomeWorkGetBo);
        return Result.ok(pageData);
    }


    @ApiOperation("获取我的作品")
    @GetMapping("/getMyHomeList")
    public Result<PageData<SvWorkVo>> getMyHomeList(SvMyWorkGetBo svMyWorkGetBo) {
        PageData<SvWorkVo> pageData = svWorkService.getUserHomeList(svMyWorkGetBo);
        return Result.ok(pageData);
    }

    @ApiOperation("获取用户作品")
    @GetMapping("/getUserList")
    public Result<PageData<SvWorkVo>> getUserList(SvWorkGetBo svWOrkGetBo) {
        PageData<SvWorkVo> pageData = svWorkService.getUserHomeList(svWOrkGetBo);
        return Result.ok(pageData);
    }

    @ApiOperation("喜欢作品")
    @PutMapping("/like")
    public Result<Void> like(@RequestParam("workId") Long workId) {
        svWorkService.like(workId, SvSecurityUtil.getUserId());
        return Result.ok();
    }

    @ApiOperation("收藏作品")
    @PutMapping("star")
    public Result<Void> star(@RequestParam("workId") Long workId) {
        svWorkService.star(workId, SvSecurityUtil.getUserId());
        return Result.ok();
    }

    @ApiOperation("上传作品")
    @PostMapping("/push")
    public Result<SvUserWorkVo> push(@RequestBody @Validated SvWorkAddBo svWorkAddBo) {
        SvUserWorkVo svUserWorkVo = svWorkService.push(svWorkAddBo);
        return Result.ok(svUserWorkVo);
    }

    @ApiOperation("获取上传作品临时密钥")
    @GetMapping("/getUpTmpKey")
    public Result<CosTmpKeyVo> getUpTmpKey(String fileName) {
        CosTmpKeyVo cosTmpKeyVo = svWorkService.getUpTmpKey(fileName);
        return Result.ok(cosTmpKeyVo);
    }

    @ApiOperation("权限设置")
    @PutMapping("/perSet")
    public Result<Void> perSet(@RequestBody @Validated WorkPerSetBo workPerSetBo) {
        svWorkService.perSet(workPerSetBo);
        return Result.ok();
    }

    @ApiOperation("删除作品")
    @DeleteMapping("/del/{workId}")
    public Result<PageData<SvUserWorkVo>> del(@PathVariable Long workId) {
        svWorkService.delMyWork(workId);
        return Result.ok();
    }


}



















